import React, {useState} from 'react'
import { withRouter } from 'react-router-dom';
import { BrowserRouter as Router, Redirect, Route, NavLink, Switch } from 'react-router-dom'
import logo from '../../img/logo.png'
import './Downmenu.css'
class Downmenu extends React.Component {

	constructor(props) {
	  super(props);
	  this.state = {
        pathname:this.props.location,
        barname:"Info Share",
        token:localStorage.getItem('token'),
        source:'/Login'
	  };
	}

    isLogin(){
        if(this.state.token){
            this.setState({
                barname:"Info Share",
                source:'/My'
            })
        }else{
            this.setState({
                barname:"登录",
                source:'/Login'
            })
        }
    }

    componentWillMount(){
        this.isLogin()
    }

	render() {
        return (
            <nav>
                <div className="navbar-div">
                    <img src={logo} alt="" id='navbar-img'></img>
                    <div className='login-text'>
                        <NavLink exact to={this.state.source}>{this.state.barname}</NavLink>    
                    </div>
                </div>
            </nav>
        )
    }
}
export default  withRouter(Downmenu);